﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace WorkStation.Frameworks.Core.Data.DataTableValidate.Rules
{
    /// <summary>
    /// * 单元格数据不能为空验证
    /// </summary>
    public class RequiredRule : RowRuleBase
    {
        public RequiredRule(string columnName) 
        {
            this.ColumnName = columnName;
        }
        
        public string ColumnName { get; set; }

        public override ValidateResult Execute(DataRow row, int line)
        {
            ValidateResult res = new ValidateResult() { IsSuccess = true };

            object value = row[this.ColumnName];

            if (value == null || string.IsNullOrEmpty(value.ToString())) 
            {
                res.IsSuccess = false;
                res.Msg = string.Format("第{0}行【{1}】列不能为空", line, this.ColumnName);
            }

            return res;
        }
    }
}
